package neu.soft.facade;

import lombok.extern.slf4j.Slf4j;
import neu.soft.entity.*;
import neu.soft.exception.AppException;
import neu.soft.exception.AppExceptionCodeMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;


/**
 * @author 李博
 * 增加个门面，减少service层耦合
 */
@Slf4j
@Component
public class SupplyComprehensiveFacade {

    @Autowired
    SupplyHandler supplyHandler;

    @Autowired
    MessageSendHandler messageSendHandler;

    //缺货购货处理
    public OperationPurchaseOrder consumeSupplyMsg(Map<String, Object> receiveMap) {
        return supplyHandler.consumeSupplyMsg(receiveMap);
    }

    //新供应商购货处理
    public OperationPurchaseOrder purchaseOrderFromVendor(Map<String, Object> map) {
        return supplyHandler.purchaseOrderFromVendor(map);
    }

    public void sendWarehouseMsg(Integer purchaseOrderId) {
        boolean res = messageSendHandler.sendPurchaseToWarehouse(purchaseOrderId);
        if (!res){
            throw new AppException(AppExceptionCodeMsg.SEND_FAIL);
        }
        log.info("发送成功");
    }


}
